package com.wuwei.elearning.utils;

import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
public class MyArrayUtils {
    public static boolean isConsecutive(List<Integer> list) {
        Collections.sort(list);
        int size = list.size();
        if (size == 0) { // 处理空列表的情况
            return true;
        }
        int first = list.get(0);
        if (first != 1) { // 列表的第一个元素必须为1
            return false;
        }
        for (int i = 1; i < size; i++) {
            int current = list.get(i);
            if (current != first + 1) {
                return false;
            }
            first = current;
        }
        return true;
    }
}
